<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>服刑信息查看</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:150px;
        }
        .input {
            width:300px;
        }
    </style>
</head>
<body>

<div class="mini-fit" style="margin-bottom: 40px;">
    <form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <!-- 用户 编辑框START-->
        <div id="editform" class="form" style="padding:10px;">
            <input name="id" id="id" class="mini-hidden" style="width: 100%;" readonly />
            <input name="orgName" class="mini-hidden" style="width: 100%;" readonly />
            <input name="priNum" id="priNum" class="mini-hidden" style="width: 100%" readonly />
            <table class="form-table" align="center" style="border-collapse:separate; border-spacing:20px;">
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>罪&emsp;&emsp;&emsp;名:</td>
                    <td class="input" onclick="itemclick('zm')" readonly>
                        <input class="mini-textarea" name="critype" id="critype" style="width: 300px;height:100px;" required="true"
                               readonly="true" onvaluechanged="onValidation()" textField="codeName" valueField="codeId" emptyText="请选择..."
                               popupHeight="50px" />
                    </td>
                    <td class="discell"><font color="#dc143c"></font>犯&emsp;罪&emsp;类&emsp;型:</td>
                    <td class="input" readonly>
                        <input class="mini-textarea" name="fzlx" id="fzlx" onclick="itemclick('fzlx')"
                               textField="codeName" valueField="codeId" emptyText="选择罪名后自动显示犯罪类型" style="width: 300px;height:100px;"
                               required="false" allowInput="false" showNullItem="true" />
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>
                        <#if "${localCode !''}"=='140000'>
                            判&nbsp;&nbsp;决&nbsp;&nbsp;刑&nbsp;&nbsp;期:
                        <#else>
                            现&emsp;刑&emsp;期:
                        </#if>
                    </td>
                    <td class="input">
                        <input name="pritime" id="pritime" readonly class="mini-combobox" onclick="itemclick('xxq')" required="true"
                               textField="codeName" valueField="codeId" emptyText="请选择..." onvaluechanged="valuechanged()"
                               allowInput="false" style="width: 300px;" />
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>附&emsp;加&emsp;刑:</td>
                    <td class="input">
                        <input name="addpenalty" id="addpenalty" class="mini-combobox" onclick="itemclick('fjx')"
                               textField="codeName" valueField="codeId" emptyText="请选择..." multiSelect="true"
                               required="true"
                               allowInput="false" style="width: 300px;"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>
                        <#if "${localCode !''}"=='140000'>
                            原判刑期始日期:
                        <#else>
                            刑&nbsp;期&nbsp;起&nbsp;日:
                        </#if>
                    </td>
                    <td class="input">
                        <input property="editor" class="mini-datepicker" id="priBegin" name="priBegin" allowInput="true"
                               style="width: 300px;"
                               required="true"/>
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>
                        <#if "${localCode !''}"=='140000'>
                            原判刑期止日期:
                        <#else>
                            刑&emsp;期&emsp;止&emsp;日:
                        </#if>
                    </td>
                    <td class="input">
                        <input property="editor" class="mini-datepicker" id="priStop" name="priStop" allowInput="true"
                               style="width: 300px;"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>案&emsp;犯&emsp;类&emsp;别:</td>
                    <td class="input">
                        <input name="aftype" id="aftype" class="mini-combobox" onclick="itemclick('aflb')"
                               textField="codeName" valueField="codeId" emptyText="请选择..." required="true"
                               allowInput="false" style="width: 300px;" />
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>逮&emsp;捕&emsp;机&emsp;关:</td>
                    <td class="input">
                        <input name="arrJg" readonly id="arrJg" class="mini-textbox" style="width: 300px;"
                               required="true"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>是否累惯犯:</td>
                    <td class="input">
                        <input name="precri" id="precri" class="mini-radiobuttonlist" readonly
                               data="[{ id: 1, name: '是' },{ id: 2, name: '否' }]" style="width: 300px;"
                               textField="name" valueField="id" value="2"/>
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>是否疾病、残疾:</td>
                    <td class="input">
                        <input name="canji" id="canji" class="mini-radiobuttonlist" readonly
                               data="[{ id: 1, name: '是' },{ id: 2, name: '否' }]" style="width: 300px;"
                               textField="name" valueField="id" value="2"/>
                    </td>
                </tr>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>捕&nbsp;前&nbsp;职&nbsp;业:</td>
                    <td class="input">
                        <input class="mini-combobox" name="bqzy" id="bqzy" style="width: 300px;" required="true"
                               textField="codeName" valueField="codeId" emptyText="请选择..." onclick="itemclick('bqzy')" popupHeight="55px"
                        />
                    </td>
                    <td class="discell">捕前&nbsp;&nbsp;职业&nbsp;&nbsp;分类:</td>
                    <td class="input">
                        <input class="mini-combobox" name="jinengtype" id="jinengtype" onclick="itemclick('zyjn')"
                               textField="codeName" valueField="codeId" emptyText="请选择..." style="width: 300px;"
                               allowInput="false" showNullItem="true" />
                    </td>
                </tr>
            </table>
        </div>
    </form>
</div>
<div style="position: absolute;bottom: 0;line-height:40px;width: 100%;border-top:1px solid #dfdfdf;text-align: center" hidden="true">
    <a class="mini-button" iconCls="fa-save" plain="true" style="font-size: 15px" onclick="saveData()">保存</a>
</div>
<script type="text/javascript">
    mini.parse();
    var data1 = []
    var form = new mini.Form("form1");
    var priNum = mini.get("priNum");
    var id = mini.get("id");
    var critype = mini.get("critype");
    var fzlx = mini.get("fzlx");
    var bqzy = mini.get("bqzy");
    var jinengtype = mini.get("jinengtype");
    var pritime = mini.get("pritime");
    var priBegin = mini.get("priBegin");
    var priStop = mini.get("priStop");
    var addpenalty = mini.get("addpenalty");
    var aftype = mini.get("aftype");

    function SetData(data) {
        var pid = priNum.getValue();
        form.setEnabled(false);
        priStop.readOnly=true;
        // 根据ID去数据库中查询数据
        $.ajax({
            url: "/azbj/inmates/getseninfo?prinum=" + pid,
            type: "post",
            dataType: "json",
            success: function (sendata) {
                var bf = mini.decode(sendata);
                if (bf != "") {
                    var bf = mini.decode(sendata);
                    form.setData(sendata);
                    form.setChanged(false);
                    mini.get("critype").setValue(bf.critype);
                    mini.get("critype").setText(bf.critypename);
                    codeIds = bf.critype;
                    mini.get("fzlx").setValue(bf.fzlx);
                    mini.get("fzlx").setText(bf.fzlxname);
                    jinengtype.setData([{codeId: bf.jinengtype, codeName: bf.jinengtypeName}]);
                    pritime.setData([{codeId: bf.pritime, codeName: bf.pritimeName}]);
                    addpenalty.setValue(bf.addpenalty);
                    addpenalty.setText(bf.addpenaltyName);
                    bqzy.setData([{codeId: bf.bqzy, codeName: bf.bqzyName}]);
                    aftype.setData([{codeId: bf.aftype, codeName: bf.aftypeName}]);
                    valuechanged();
                }
            }
        });
    }

    function onValidation() {
        var critypeValue = critype.getValue();
        if (critypeValue.length <= 2) {
            critype.setRequired(true);
        }

    }

    function saveData() {
        var critypeValue = critype.getValue();
        if (critypeValue.length <= 2) {
            critype.setRequired(true);
        }
        var addpenaltyId = mini.get("addpenalty").getValue();//拿到选中附加刑的id
        var text = mini.get("addpenalty").getText();
        if (addpenaltyId.length > 2) {
            var idsArr = addpenaltyId.split(',');
            for (var i = 0; i < idsArr.length; i++) {
                if ("05" == idsArr[i]) {
                    idsArr.splice(i, 1)
                    delete idsArr[idsArr]
                }
            }
            mini.get("addpenalty").setValue(idsArr.join(','));
            mini.get("addpenalty").setText(text);
        }
        var prival = priNum.getValue();
        form.validate();
        if (form.isValid() == false) {
            return;
        }
        var zuiming = mini.get("critype").getValue();
        if (zuiming == '-1' || zuiming == '') {
            mini.alert("请选择罪名");
            return;
        }
        var data = form.getData();
        var json = mini.encode(data);
        if (prival == "") {
            mini.alert("请先保存基本信息");
        } else {
            //校验刑期起日和刑期止日
            if (priBegin.getValue() != "" && priStop.getValue() != "") {
                if (priBegin.getValue() > priStop.getValue()) {
                    mini.alert("刑期起日应该小于刑期止日");
                    return;
                }
            }
            commonSaveData("/azbj/sentence/save", {data: json}, callback);

            // 保存成功的回调函数
            function callback() {
                mini.alert("保存成功");
            }
        }
    }

    window.onload = function () {
        priNum.setValue(${priNum!''});
        if (priNum.getValue() == "") {
            mini.alert("请先保存基本信息");
        } else {
            SetData();
        }
    }

    function itemclick(e) {
        if (e == 'zm') {
            critype.setRequired(false);
            mini.open({
                url: "/azbj/yazgl/inmates/sentence/zuiming",
                title: "罪名信息",
                width: 600,
                height: 520,
                allowResize: false,
                showCloseButton: false,
                onload: function () {
                },
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData(); // 跨页面传值
                        data1 = mini.clone(data);
                        mini.get("critype").setValue(data1.codeId);
                        mini.get("critype").setText(data1.codeName);
                        onValidation();
                        getParentCodeNames(data1.codeId);
                    }
                }
            });
        }
        if (e == 'fzlx') {
            var fzlx = mini.get("fzlx");
        }
        if (e == 'zyjn') {
            var jinengtype = mini.get("jinengtype");
            jinengtype.setUrl("/azbj/inmates/baseinfo/getTbsysCode?codeType=2_15&pcodeId=0&sn=1");
        }
        if (e == 'xxq') {
            var pritime = mini.get("pritime");
            pritime.setUrl("/azbj/inmates/baseinfo/getTbsysCode?codeType=2_14&pcodeId=-1&sn=0");
        }
        if (e == 'fjx') {
            var addpenalty = mini.get("addpenalty");
            addpenalty.setUrl("/azbj/inmates/baseinfo/getTbsysCode?codeType=1_8&pcodeId=-1&sn=-1");

        }
        if (e == 'aflb') {
            var aftype = mini.get("aftype");
            aftype.setUrl("/azbj/inmates/baseinfo/getTbsysCode?codeType=1_92&pcodeId=-1&sn=-1");
        }
        if (e == 'bqzy') {
            mini.open({
                url: "/azbj/yazgl/inmates/sentence/vocation",
                title: "职业信息",
                width: 600,
                height: 520,
                allowResize: false,
                showCloseButton: false,
                onload: function () {
                },
                ondestroy: function (action) {
                    if (action == "ok") {
                        var iframe = this.getIFrameEl();
                        var data = iframe.contentWindow.GetData(); // 跨页面传值
                        data = mini.clone(data);
                        bqzy.setData([{codeId: data.codeId, codeName: data.codeName}]);
                        bqzy.select(0);
                    }
                }
            });
        }
    }

    function getParentCodeNames(codeIds) {
        if (codeIds != undefined && codeIds != null && codeIds != '') {
            $.ajax({
                url: "/azbj/inmates/sentence/syscode?codeIds=" + codeIds,
                type: 'post',
                async: false,
                success: function (data) {
                    var res = data.data;
                    var name = ''
                    var codeIds = ''
                    var nameType = '';
                    for (var i = 0; i < res.length; i++) {
                        if (i == 0) {
                            name = res[i].codeName;
                            codeIds = res[i].codeId;
                        } else if (i > 0 && i < res.length - 1) {
                            name = name + ',' + res[i].codeName;
                            codeIds = codeIds + ',' + res[i].codeId;
                        }
                        if (i == res.length - 1) {
                            nameType = res[i].codeType;
                        }
                    }
                    mini.get("critype").setValue(codeIds);
                    mini.get("critype").setText(name);
                    mini.get('fzlx').setValue(codeIds);
                    mini.get('fzlx').setText(nameType);
                }
            });
        } else {
            mini.get('fzlx').setValue("");
            mini.get('fzlx').setText("");
        }
    }

    function valuechanged(e) {
        var pritime = mini.get("pritime");
        var pritimeval = pritime.getValue();
        var priStop = mini.get("priStop");
        if (pritimeval == "9997" || pritimeval == "9996" || pritimeval == "9995") {
            priStop.disable();
            priStop.setValue("");
        } else {
            priStop.enable();
        }
    }
</script>
</body>
</html>